package com.drought.rained.base;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.Locale;
import java.util.Random;

public abstract class BaseActivity extends AppCompatActivity {
    ILoading mLoading;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        initLocaleLanguage();
        super.onCreate(savedInstanceState);
        mLoading = createLoadingView();
    }

    protected abstract ILoading createLoadingView();

    /**
     * 获取layoutId
     *
     * @return
     */
    protected abstract int getResId();

    /**
     * 选择语言资源
     */
    private void initLocaleLanguage() {
        Resources resources = getApplicationContext().getResources();
        Configuration configuration = resources.getConfiguration();
        configuration.locale = new Locale(Locale.getDefault().getLanguage());
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());//更新配置
    }


    // Loading框
    public void showLoadingView() {
        if (mLoading != null && !mLoading.isShowing()) {
            mLoading.showLoading();
        }
    }

    public void dismissLoadingView() {
        if (mLoading != null && mLoading.isShowing()) {
            mLoading.dismissLoading();
        }
    }

}
